package cn.elves.model.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.elves.model.user.entity.po.VerificationCode;
import cn.elves.model.user.service.VerificationCodeService;
import cn.elves.model.user.mapper.VerificationCodeMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author pc
 * @description 针对表【tb_verification_code】的数据库操作Service实现
 * @createDate 2024-06-09 13:01:12
 */
@Service
public class VerificationCodeServiceImpl extends ServiceImpl<VerificationCodeMapper, VerificationCode>
        implements VerificationCodeService {

    @Resource
    private VerificationCodeMapper verificationCodeMapper;

    @Override
    public Boolean checkCode(String phone, String code) {
        VerificationCode verificationCode = verificationCodeMapper.selectOne(new QueryWrapper<VerificationCode>()
                .eq("phone", phone)
                .eq("verification_code", code)
                .orderByDesc("create_time")
                .last("limit 1"));
        return !verificationCode.getIscheck();
    }
}




